#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
const int INF=0x3f3f3f3f;
#include <cstring>
#include <functional>
using namespace std;
#define DEBUG
const int N=110;

struct Node{
    int w;
    int fa, l, r;
}tr[N];
bool st[N];

int n, ans=INF;

void dfs(int u, int deep, int& val)
{
    val+=tr[u].w*deep;
    st[u]=true;
    if(tr[u].fa&&!st[tr[u].fa]) dfs(tr[u].fa, deep+1, val);
    if(tr[u].l&&!st[tr[u].l]) dfs(tr[u].l, deep+1, val);
    if(tr[u].r&&!st[tr[u].r]) dfs(tr[u].r, deep+1, val);
}

void init()
{
    read(n);
    for(int i=1; i<=n; i++)
    {
        read(tr[i].w); read(tr[i].l); read(tr[i].r);
        tr[tr[i].l].fa=i; tr[tr[i].r].fa=i;
    }
}

void solve()
{
    init();
    for(int i=1; i<=n; i++)
    {
        int val=0;
        memset(st, 0, sizeof st);
        dfs(i, 0, val);
        ans=min(ans, val);
        // printf("cal(%d):%d\n", i, val);
    }
    quickwrite(ans); puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        // freopen("./out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
